import time

from selenium.webdriver.common.by import By

from base.page_base import BasePage


class RegisterPage(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.phone = (By.ID, "phone")
        self.password = (By.ID, "password")
        self.code = (By.ID, "verifycode")
        self.get_phone_code = (By.ID, "get_phone_code")
        self.phone_code = (By.ID, "phone_code")
        self.submit = (By.CLASS_NAME, "lg-btn")
        self.success_result = (By.XPATH, '//*[@id="step3"]/div/div/h1')
        self.error_result = (By.XPATH, '//*[@id="reg_form"]/div[1]')

    def register(self, phone, password, code, phone_code="666666"):
        # time.sleep(1)
        self.fd_element(self.phone).send_keys(phone)
        self.fd_element(self.password).send_keys(password)
        self.fd_element(self.code).send_keys(code)
        self.fd_element(self.get_phone_code).click()
        time.sleep(2)
        self.fd_element(self.phone_code).send_keys(phone_code)
        self.fd_element(self.submit).click()

    def get_success_result(self):
        time.sleep(2)
        return self.fd_element(self.success_result).text

    def get_error_result(self):
        time.sleep(1)
        return self.fd_element(self.error_result).text
        # 获取注册结果



